//
//  QDTicketTableViewCell.swift
//  QDMetroClient
//
//  Created by YueWen on 2019/3/3.
//  Copyright © 2019 YueWen. All rights reserved.
//

import UIKit

/// 车票的
final class QDTicketTableViewCell: NWTableViewCell {

    /// 按钮点击的响应
    var actionButtonTapHandler:(()->())?
    /// 开始车站
    let startLabel = UILabel()
    /// 箭头
    private let arrowImageView = UIImageView()
    /// 结束车站
    let endLabel = UILabel()
    /// 展示购买数量和总价的样式
    let subtitleLabel = UILabel()
    /// 支付时间
    let timeLabel = UILabel()
    /// 响应按钮
    let actionButton = UIButton()
    /// 状态的图片
    let statusImageView = UIImageView()
    
    override func buildView() {
        super.buildView()
        
        bottomLineInset.left = 15
        bottomLineInset.right = 15
        bottomLineHeight = 0.5
        bottomLineView.backgroundColor = #colorLiteral(red: 0.9294117647, green: 0.9411764706, blue: 0.9333333333, alpha: 1)
        
        startLabel.text = "太平角公园(一疗)"
        startLabel.font = Font.medium.font(size: 15)
        startLabel.textColor = QDColors.black
        
        arrowImageView.image = "mp_st_arrow_right".namedImage
        
        endLabel.text = "太平角公园(一疗)"
        endLabel.font = Font.medium.font(size: 15)
        endLabel.textColor = QDColors.black
        
        subtitleLabel.font = Font.regular.font(size: 13)
        subtitleLabel.textColor = QDColors.gray2
        subtitleLabel.text = "购买数量：1张  |  总价：2.00元"
        
        timeLabel.textColor = QDColors.gray
        timeLabel.font = Font.regular.font(size: 13)
        timeLabel.text = "支付时间：2019年03月03日 16:07"
        
        statusImageView.backgroundColor = .white
        
        actionButton.setTitle("扫码取票", for: .normal)
        actionButton.setTitleColor(QDColors.theme, for: .normal)
        actionButton.clipsToBounds = true
        actionButton.layer.cornerRadius = 11
        actionButton.layer.borderWidth = 0.5
        actionButton.layer.borderColor = QDColors.theme.cgColor
        actionButton.titleLabel?.textAlignment = .center
        actionButton.titleLabel?.font = Font.regular.font(size: 13)
        actionButton.addTarget(self, action: #selector(actionButtonDidTap), for: .touchUpInside)
        
        contentView.addSubview(startLabel)
        contentView.addSubview(arrowImageView)
        contentView.addSubview(endLabel)
        contentView.addSubview(subtitleLabel)
        contentView.addSubview(timeLabel)
        contentView.addSubview(actionButton)
        contentView.addSubview(statusImageView)
        
        startLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(15)
            make.top.equalToSuperview().offset(20)
            make.height.equalTo(20)
        }
        
        arrowImageView.snp.makeConstraints { (make) in
            make.height.width.equalTo(10)
            make.centerY.equalTo(startLabel)
            make.left.equalTo(startLabel.snp.right).offset(5)
        }
        
        endLabel.snp.makeConstraints { (make) in
            make.left.equalTo(arrowImageView.snp.right).offset(5)
            make.centerY.equalTo(startLabel)
            make.height.equalTo(20)
        }
        
        subtitleLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(15)
            make.top.equalTo(startLabel.snp.bottom).offset(8)
            make.height.equalTo(18)
        }
        
        timeLabel.snp.makeConstraints { (make) in
            make.top.equalTo(subtitleLabel.snp.bottom).offset(8)
            make.height.equalTo(18)
            make.left.equalToSuperview().offset(15)
        }
        
        actionButton.snp.makeConstraints { (make) in
            make.height.equalTo(22)
            make.width.equalTo(64)
            make.right.equalToSuperview().inset(20)
            make.centerY.equalTo(timeLabel)
        }
        
        statusImageView.snp.makeConstraints { (make) in
            make.width.height.equalTo(60)
            make.top.right.equalToSuperview()
        }
    }
    
    @objc func actionButtonDidTap(){
        actionButtonTapHandler?()
    }
}
